import numpy as np
from scipy import signal
from sklearn.decomposition import FastICA
import matplotlib.pyplot as plt
import librosa
from pylab import mpl
# 设置显示中文字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams['axes.unicode_minus'] = False
audio_path = r"E:\dogbarkdata\AudioClassification\dataset\dogbarking\audio\fold0\0gkLHfHJSnI_80_90_cut.mp3"
y, sr = librosa.load(audio_path)
X = y.reshape(-1, 1)



f0, voiced_flag, _ = librosa.pyin(y, fmin=librosa.note_to_hz('C2'), fmax=librosa.note_to_hz('C7'))
print(f0[voiced_flag])  # 只保留有声部分的基本频率